package com.bskms.controller;

import com.bskms.utils.PropertyUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 校园地图控制器
 * <p>提供校园地图页面，集成高德地图，展示幼儿园园址信息。</p>
 * <p>Windows 11 开发环境下可直接运行；页面通过 Thymeleaf 渲染配置项。</p>
 */
@Controller
@RequestMapping("/map")
public class MapController {

    /**
     * 跳转到校园地图页面
     * <p>从 config.properties 中读取下列配置并传递给前端：</p>
     * <ul>
     *     <li>amap.key：高德 Web JS API 的 Key</li>
     *     <li>school.name：幼儿园名称</li>
     *     <li>school.address：幼儿园详细地址</li>
     *     <li>school.lng：经度（GCJ-02，高德坐标系）</li>
     *     <li>school.lat：纬度（GCJ-02，高德坐标系）</li>
     * </ul>
     *
     * @param model 视图模型
     * @return String 返回模板路径 user/campusMap
     */
    @RequestMapping("/campus")
    public String campusMap(Model model) {
        String amapKey = PropertyUtil.getConfigureProperties("amap.key");
        String schoolName = PropertyUtil.getConfigureProperties("school.name");
        String schoolAddress = PropertyUtil.getConfigureProperties("school.address");
        String lng = PropertyUtil.getConfigureProperties("school.lng");
        String lat = PropertyUtil.getConfigureProperties("school.lat");

        model.addAttribute("amapKey", amapKey == null ? "09341f7551760c3907c387526b0629bc" : amapKey);
        model.addAttribute("schoolName", schoolName == null ? "幼儿园" : schoolName);
        model.addAttribute("schoolAddress", schoolAddress == null ? "请在 config.properties 配置 school.address" : schoolAddress);
        model.addAttribute("lng", lng == null ? "116.397389" : lng); // 默认北京天安门经度
        model.addAttribute("lat", lat == null ? "39.908722" : lat);  // 默认北京天安门纬度
        return "user/campusMap";
    }
}
